package main;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;

public class PostXml {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><simcoupon><head><tradeType>RndGetRequest</tradeType></head><body></body></simcoupon>";
		String url = "http://localhost:8082/cios_manage/servlet/MyServlet.htm";

		HttpClient httpclient = new HttpClient();
		PostMethod post = new PostMethod(url);
		String info = null;
		try {
			RequestEntity entity = new StringRequestEntity(data, "text/xml",
					"utf-8");
			post.setRequestEntity(entity);
			httpclient.executeMethod(post);
			int code = post.getStatusCode();
			if (code == HttpStatus.SC_OK)
				info = new String(post.getResponseBodyAsString());
			System.out.println("info:" + info);
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			post.releaseConnection();
		}
	}

}
